package coreservlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;

@WebServlet("/Abreviere")
public class GasesteAbreviere extends HttpServlet {
  private ServiceAbreviere abbreviationMapper = new HartaAbreviere();
  
  @Override
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    String stateName = request.getParameter("state-name");
    if (stateName == null) {
      stateName = "";
    }
    stateName = stateName.trim();
    String stateAbbreviation = abbreviationMapper.findAbbreviation(stateName);
    StareJudet stateInfo = new StareJudet(stateName, stateAbbreviation);
    request.setAttribute("InfoJudet", stateInfo);
    String address;
    
    String c="Bucuresti";
	if (stateName.isEmpty()) {
      address = "/WEB-INF/rezultate/JudetNeexistent.jsp";
    } else if (stateAbbreviation != null) {
      address = "/WEB-INF/rezultate/Abreviere.jsp";
    } else if (stateName.valueOf(c) != null) {
        address = "/WEB-INF/rezultate/Bucuresti.jsp";
    } else {
      address = "/WEB-INF/rezultate/JudetNecunoscut.jsp";
    }
    
    
    
    RequestDispatcher dispatcher =
      request.getRequestDispatcher(address);
    dispatcher.forward(request, response);
  }
}
